/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.chen.javadesignpattern;

/**
 *
 * @author scorpius
 */
public class FactoryMode {
    public static void main(String[] args) {
        ShapeFactory shapeFactory = new ShapeFactory();
        Shape shape = shapeFactory.getShape("Rectangle");
        System.out.println(shape.getClass().getName());
    }
}

interface Shape{
    void draw();
}

//矩形
class Rectangle implements Shape{

    @Override
    public void draw() {
        System.out.println("Inside Rectangle::draw() method.");
    }
  
}
//三角形
class Square implements Shape{

    @Override
    public void draw() {
        System.out.println("Inside Square::draw() method.");
    }
    
}
//圆形
class Circle implements Shape{

    @Override
    public void draw() {
        System.out.println("Inside Circle::draw() method.");
    }
    
}

class ShapeFactory{
    Shape getShape(String type){
        if(null == type){
            return null;
        }
        if(type.equalsIgnoreCase("Circle")){
            return new Circle();
        }else if(type.equalsIgnoreCase("Rectangle")){
            return new Rectangle();
        }else if(type.equalsIgnoreCase("Square")){
            return new Square();
        }
        return null;
    }
}